package cm.server.dao;

import cm.server.entity.area;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

//service通过@Resource调用
@Repository
public interface areaRepository extends JpaRepository<area, Long> {
    //    @Query(value = "select * from sensor_log where time>?1 and time<?2 and day=?3", nativeQuery = true)
//    List<SensorLog> findAllByPeriod(int startTime, int endTime, int day);
    //    实现查找
    @Query(value = "select * from area_people where day=?1 and area_id=?2 and time=?3", nativeQuery = true)
    List<area> findAllByDayAndAreaAndTime(Integer day, Integer area, Integer time);

    @Query(value = "select * from area_people where day = ?1 and area_id = ?2", nativeQuery = true)
    List<area> findAllByAreaAndDay(Integer day, Integer area);

    @Query(value = "select * from area_people where area_id = ?1", nativeQuery = true)
    List<area> findAllByArea(Integer area);

    @Query(value = "select * from  area_people where day = ?1 and area_id=?2", nativeQuery = true)
    List<area> findNumByDayAndArea(Integer day, int areaId);

    @Query(value = "select * from  area_people where day = ?1 and time = ?2", nativeQuery = true)
    List<area> findNumByDayAndTime(Integer day, Integer time);

    @Query(value = "select distinct time from area_people where day=?1", nativeQuery = true)
    List<Integer> findDistinctTime(int day);

    List<area> findByArea(Integer area);

    List<area> findByTime(Integer time);

    List<area> findByNum(Integer num);

    List<area> findByDensity(Float density);

    //    实现删除
    void deleteAllByArea(int area);

    void deleteByArea(int area);

}
